using OracleInternal.Common;
using OracleInternal.ServiceObjects;

namespace OracleInternal.TTC
{
	internal class NotificationHeader
	{
		internal static int STOP_TFN_KPDNRNF = 4;

		internal static int CONS_CLOSE_ERR = 24035;

		internal static int DEST_CLOSE_ERR = 24010;

		private OracleConnectionImpl m_orclConnImpl;

		internal int m_messageType;

		internal long m_regId;

		internal NotificationHeader(OracleConnectionImpl orclConnImpl)
		{
			m_orclConnImpl = orclConnImpl;
		}

		internal void Receive()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.NotificationHeader, OracleTraceFuncName.Receive, "WAITING for Notification...");
			}
			try
			{
				m_messageType = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				int num = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				m_regId = m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					string text = "Ntf Header Received: MsgType=" + m_messageType + ", SvrRegId=" + m_regId + ", ErrCode=" + num;
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.TTC, OracleTraceClassName.NotificationHeader, OracleTraceFuncName.Receive, text);
				}
				if (m_messageType == STOP_TFN_KPDNRNF)
				{
					if (ProviderConfig.m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.TTC, OracleTraceClassName.NotificationHeader, OracleTraceFuncName.Receive, "Received MsgType STOP_TFN_KPDNRNF");
					}
					NotificationContext.EnqueueNotification(m_orclConnImpl, m_regId, m_orclConnImpl.m_marshallingEngine.m_dbCharSetConv, 0, 0, null, bLastNotification: true);
				}
				int num2 = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				if (num2 > 0)
				{
					byte[] array = new byte[num2];
					int[] array2 = new int[1];
					m_orclConnImpl.m_marshallingEngine.UnmarshalCLR(array, 0, array2, array.Length);
					num2 = array2[0];
				}
				int num3 = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				if (num3 > 0)
				{
					byte[] array3 = new byte[num3];
					int[] array4 = new int[1];
					m_orclConnImpl.m_marshallingEngine.UnmarshalCLR(array3, 0, array4, array3.Length);
					num3 = array4[0];
				}
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.NotificationHeader, OracleTraceFuncName.Receive);
				}
			}
		}
	}
}
